/**
 * 给定N，K，构造一个Klevel的N排列 
 * 所谓Klevel是指：排列中任意连续K个数之和上下浮动不超过1
 * 简单打表观察一下可以按照如下规律放：
 * 1 .... 2 .... 3 ....
 * 其中1、2之间有K-1个位置，最后一段剩余的位置将最后剩下的数全部放进去即可
 * 注意到N必须要大于K，否则无意义，所以一定能够放下2
 */
#include <bits/stdc++.h>
using namespace std;

using llt = long long;
using vi = vector<int>;
using value_t = int;

int N, K;

bool check(const vi & a){
    auto s = accumulate(a.begin(), a.end() + K, 0LL);
    int mmin = s, mmax = s;
    for(int i=K;i<N;++i){
        s += a[i] - a[i - K];
        mmin = min(mmin, s);
        mmax = max(mmax, s);
    }
    return mmax - mmin <= 1;
}

void proc(){
    if(N <= K + K){
        vi a(N);
        int cur = 1;
        int p = 0;
        int o = 1;
        while(1){
            if(p + K < N){
                if(o){
                    a[p] = cur;
                    a[p + K] = cur + 1;                    
                }else{
                    a[p] = cur + 1;
                    a[p + K] = cur;
                }
                o ^= 1;
                cur += 2;
                p += 1;
            }else{
                while(p < N and a[p] == 0){
                    a[p++] = cur++;
                }
            }
            if(cur == N + 1) break;
        }
        // assert(check(a));
        for(auto i : a) cout << i << " ";
        cout << "\n";
        return;
    }
    
    vi a(N, 0);
    int cur = 1;
    int p = 0;
    vi tmpvec(N);
    int o = 1;
    while(1){
        int j = 0;
        for(int i=p;i<N;i+=K){
            tmpvec[j++] = cur++;
        }
        if(o){
            for(int i=p,j=0;i<N;i+=K,++j){
                a[i] = tmpvec[j];
            } 
        }else{
            for(int i=p,u=j-1;i<N;i+=K,--u){
                a[i] = tmpvec[u];
            } 
        }
        o ^= 1;
        if(cur == N + 1) break;
        p += 1;
    }
    assert(check(a));
    for(auto i : a) cout << i << " ";
    cout << "\n";
    return;    
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1; 
    cin >> nofkase;
    while(nofkase--){
        cin >> N >> K;
        // A.assign(N, {});
        // B.assign(M, {});
        // for(auto & i : A) cin >> i;
        // for(auto & i : B) cin >> i;
        proc();  
    }
    return 0;
}